package de.akabahn.ebd.control.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayDeque;
import java.util.Date;
import java.util.Deque;

public class DebugDataContainer {

	private static DebugDataContainer instance;
	private static DateFormat DF = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss.SSS");

	private Deque<String> queue;

	public DebugDataContainer() {
		queue = new ArrayDeque<String>(100);
	}

	public synchronized void add(String caller, String data) {
		String entry = DF.format(new Date()) + " | " + caller + " | " + data;
		queue.offerFirst(entry);
		if (queue.size() > 100) {
			queue.removeLast();
		}
	}

	public Deque<String> getQueue() {
		return queue;
	}

	public static DebugDataContainer getInstance() {
		if (instance == null) {
			instance = new DebugDataContainer();
		}

		return instance;
	}
}
